package com.example.myapplication;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.media.Image;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.example.myapplication.Adapter.PyqItemAdapter;
import com.example.myapplication.Bean.PyqItem;

import org.litepal.LitePal;

import java.util.Collections;
import java.util.List;

import static org.litepal.LitePalApplication.getContext;

public class PyqActivity extends AppCompatActivity {

    private ImageView postpyq, userimg, pyq_thumbs_up;
    private NoScrollListView pyqlv;
    private TextView username, pyq_comment_txt;
    private EditText editText1;
    private Button pyq_comment;

    PyqItemAdapter adapter;
    List<PyqItem> pyqItemList;
    //    切换图片所需
//    boolean isChanged = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pyq);
        EditText editText1 = findViewById(R.id.edit_dialog);
        initView();
        setListener();
    }

    private void setListener() {
        /*点击相机 跳转到编辑朋友圈发送页面*/
        postpyq.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent1 = new Intent(PyqActivity.this, PostActivity.class);
                startActivity(intent1);
                finish();

            }
        });

//点赞功能的实现
//        pyq_thumbs_up.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if (v == pyq_thumbs_up) {
//                    if (isChanged) {
//                        pyq_thumbs_up.setImageDrawable(getResources().getDrawable(R.mipmap.dianzan8a));
//                    } else {
//                        pyq_thumbs_up.setImageDrawable(getResources().getDrawable(R.mipmap.pinkdianzan));
//                    }
//                    isChanged = !isChanged;
//
//                }
//            }
//        });


//        点击评论功能
//        pyq_comment.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
////                所在的activity
//                androidx.appcompat.app.AlertDialog.Builder builder = new AlertDialog.Builder(PyqActivity.this);
//                final View v = LayoutInflater.from(PyqActivity.this).inflate(R.layout.dialog_customize, null);
//                builder.setIcon(R.mipmap.bi);
//                builder.setTitle("更改昵称");
////                创建视图
//                builder.setView(v);
//                builder.setNegativeButton("取消", null);
//                builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
//                    @Override
//                    public void onClick(DialogInterface dialogInterface, int i) {
//                        // 获取EditView中的输入内容
//                        EditText edit_dialog = v.findViewById(R.id.edit_dialog);
////                        把 获取EditView中的输入内容 传入到TextView中
//                        pyq_comment_txt.setText(edit_dialog.getText().toString());
//                    }
//                });
//
//                builder.create().show();
//            }
//        });

    }

    private void initView() {

        postpyq = findViewById(R.id.postpyq);
        userimg = findViewById(R.id.userimg);
        pyqlv = findViewById(R.id.pyqlv);
        username = findViewById(R.id.username);
        pyq_thumbs_up = (ImageView) findViewById(R.id.pyq_thumbs_up);
        pyq_comment = findViewById(R.id.pyq_comment);
        pyq_comment_txt = findViewById(R.id.pyq_comment_txt);

        /* */
        pyqItemList = LitePal.findAll(PyqItem.class);

        Collections.reverse(pyqItemList);

        /*     适配器  数据源   子线布局*/
        adapter = new PyqItemAdapter(PyqActivity.this, R.layout.pyq_item, pyqItemList);

        pyqlv.setAdapter(adapter);



        /* SharedPreferences存入图片*/
//        同步朋友圈头像
        SharedPreferences sp = getSharedPreferences("userinfo", MODE_PRIVATE);
        userimg.setImageResource(sp.getInt("myimg", -1));
        username.setText(sp.getString("myname", ""));
    }
}
